#!/usr/bin/env python
# -*- coding:GBK -*-
import os
import os.path
from sgmllib import SGMLParser
class AnalyseJavaHtml(SGMLParser):
    def __init__(self):
      SGMLParser.__init__(self)
      self.ispre=False
      self.isbr=False
      self.sourceCode=''
    def start_pre(self,attrs):
        self.ispre=True
    def handle_data(self, text):
        if self.ispre==True:
            self.sourceCode=text.replace('&lt;','<')
            self.sourceCode=False
if __name__ == '__main__':
    zipFileNameList=[]
    readPath='E:\\Temp\\sql'
    writePath='E:\\Temp\\convertedsql'
    codeMap={}
    executeFile=open(writePath+'\\'+'script.sql','w')
    for root,dirnames,filenames in os.walk(readPath):
        for filename in filenames:
            print filename
            if not filename.endswith('.sql'):
                continue
            #if not filename=='SQL04010120.sql':continue
            executeFile.write('prompt execute script '+filename+'\n')
            executeFile.write('@@'+filename+'\n')
            orialFile=open(os.path.join(root,filename),'r');
            destFile=open(os.path.join(writePath,filename),'w')
            i=0
            destFile.write('set feedback off\n')
            destFile.write('set define off\n')
            for line in orialFile:
                i+=1;
                if line.startswith('prompt'):
                    line='--'+line
                elif line.startswith(' insert into dm_call_log_04'):
                    line=line.rstrip()+';'
                else:continue
                if i%500==0:
                    line+='\n commit;'
                    line+='\n prompt 500 records loaded '
                destFile.write(line+'\n')
            destFile.write('commit;\n')
            destFile.write('prompt total '+str(i)+' records loaded\n')
            destFile.close()
    executeFile.close()
